package com.ly.hotel.util;

import java.util.Locale;

import com.ly.hotel.common.MyApplication;

public class LanguageUtil {
/*	
	locale = Locale.ENGLISH;//英文
	locale = Locale.SIMPLIFIED_CHINESE;//中文
	locale = Locale.TRADITIONAL_CHINESE;//繁体中文
	*/
/*	
	语言是用分号分割的，规定->>  中文;英文;繁体中文
	*/
	public static String getTextFromLocalLanguage(String str){
//		Log.i("language", "当前系统语言" + MyApplication.currectLocale.toString());
		
		String rv = "";
		if(str != null){
			if(str.contains(";")){
				String lang[] = str.split(";");
//				Log.i("language", lang.length + "," + str);
				if(lang.length == 2){
					if(isZH()){
						rv = lang[0];
					}else if(isEN()){
						rv = lang[1];
						if(rv.equals(""))
							rv = lang[0];
					}else{//默认是中文
						rv = lang[0];
					}
				}else if(lang.length >= 3){
					if(isZH()){
						rv = lang[0];
					}else if(isEN()){
						rv = lang[1];
						if(rv.equals(""))
							rv = lang[0];
					}else if(isZhTW()){
						rv = lang[2];
						if(rv.equals(""))
							rv = lang[0];
					}else{//默认是中文
						rv = lang[0];
					} 
				}
			} else {
				rv = str;
			}
		}
		return rv;
	}

	public static String getTextFromLocalLanguage(String str,String split){

		String rv = "";
		if(str != null){
			if(str.contains(";;")){
				String lang[] = str.split(split);
				if(lang.length == 2){
					if(isZH()){
						rv = lang[0];
					}else if(isEN()){
						rv = lang[1];
						if(rv.equals(""))
							rv = lang[0];
					}else{//默认是中文
						rv = lang[0];
					}
				}else if(lang.length >= 3){
					if(isZH()){
						rv = lang[0];
					}else if(isEN()){
						rv = lang[1];
						if(rv.equals(""))
							rv = lang[0];
					}else if(isZhTW()){
						rv = lang[2];
						if(rv.equals(""))
							rv = lang[0];
					}else{//默认是中文
						rv = lang[0];
					}
				}
			} else {
				rv = str;
			}
		}
		return rv;
	}

	public static String getTextFromLocalLanguage(Locale locale,String str,String split){

		String rv = "";
		if(str != null){
			if(str.contains(";;")){
				String lang[] = str.split(split);
				if(lang.length == 2){
					if(locale.equals(Locale.SIMPLIFIED_CHINESE)){
						rv = lang[0];
					}else if(locale.equals(Locale.ENGLISH)){
						rv = lang[1];
						if(rv.equals(""))
							rv = lang[0];
					}else{//默认是中文
						rv = lang[0];
					}
				}else if(lang.length >= 3){
					if(locale.equals(Locale.SIMPLIFIED_CHINESE)){
						rv = lang[0];
					}else if(locale.equals(Locale.ENGLISH)){
						rv = lang[1];
						if(rv.equals(""))
							rv = lang[0];
					}else if(locale.equals(Locale.TRADITIONAL_CHINESE)){
						rv = lang[2];
						if(rv.equals(""))
							rv = lang[0];
					}else{//默认是中文
						rv = lang[0];
					}
				}
			} else {
				rv = str;
			}
		}
		return rv;
	}
	
	public static boolean isZH() {
		Locale locale = MyApplication.currectLocale;
		if (locale.equals(Locale.SIMPLIFIED_CHINESE)){
//			Log.i("language", "简体中文");
			return true;
		} else{
			return false;
		}
	}
	
	public static boolean isEN() {
		Locale locale = MyApplication.currectLocale;
		if (locale.equals(Locale.ENGLISH)){
//			Log.i("language", "英文"); 
			return true;
		} else{
			return false;
		}
	}
	
	public static boolean isZhTW() {
		Locale locale = MyApplication.currectLocale;
		if (locale.equals(Locale.TRADITIONAL_CHINESE)){
//			Log.i("language", "繁体中文");
			return true;
		} else{
			return false;
		}
	}
}
